﻿using MyKTV;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace HolidaysDemo2
{
    public partial class Form2 : Form
    {
        DBHelper dBHelper = new DBHelper();
        DataSet ds = new DataSet();
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            dBHelper.Openconnection();
            string sql = "select * from StationInfo";
            SqlDataAdapter adapter = new SqlDataAdapter(sql,dBHelper.Connection);
            adapter.Fill(ds, "StationInfo");

            comboBox1.DataSource = ds.Tables["StationInfo"];
            comboBox1.ValueMember = "StationID";
            comboBox1.DisplayMember = "StationName";

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Clear();
        }

        private void Clear()
        {
            this.comboBox1.Text = "月球一号监测站";
            this.textBox1.Text = null;
            this.textBox2.Text = null;
            this.textBox3.Text = null;
            this.textBox4.Text = null;
            this.textBox5.Text = null;
            this.textBox6.Text = null;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Equals(string.Empty) || this.textBox2.Text.Equals(string.Empty) ||this.textBox3.Text.Equals(string.Empty) || this.textBox4.Text.Equals(string.Empty) || this.textBox5.Text.Equals(string.Empty) )
            {
                MessageBox.Show("所有信息均不能为空,请完善");
                return;
            }
            else
            {
                int jc = 1;
                if (comboBox1.Text=="月球一号监测站")
                {
                    jc = 1;
                }
                else if (comboBox1.Text == "月球二号监测站")
                {
                    jc = 2;
                }
                else if (comboBox1.Text == "火星一号监测站")
                {
                    jc = 3;
                }
                else if (comboBox1.Text == "火星二号监测站")
                {
                    jc = 4;
                }
                else if (comboBox1.Text == "木星一号监测站")
                {
                    jc = 5;
                }
                else if (comboBox1.Text == "地球一号监测站")
                {
                    jc = 6;
                }
                if (textBox6.Text.Trim()==null)
                {
                    this.textBox6.Text = "无";
                }

                string sql= "insert AirQualityInfo(StationID,InputName,StartDate,EndDate,PM,Level,Notes) values('"+jc+"', '"+this.textBox1.Text+"', '"+this.textBox2.Text+"', '"+this.textBox3.Text+"', '"+this.textBox4.Text+"', '"+this.textBox5.Text+"', '"+this.textBox6.Text+"')";
                SqlCommand command = new SqlCommand(sql,dBHelper.Connection);
                command.ExecuteNonQuery();
                MessageBox.Show("数据已经成功保存");
                Clear();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
